@extends('Admin.base')
@section('css')
    <link rel="stylesheet" href="/Admin/layuiadmin/css/extend/formSelects-v4.css" media="all">
@endsection
@section('style')

@endsection
@section('content')
    <div class="layui-card">
        <form class="layui-form" id="layui-form" action="{{url('admin/menu/')}}{{isset($data) ? '/'.$data->id : ''}}" method="post">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>{{isset($data) ? '编辑菜单' : '新增菜单'}}</legend>
            </fieldset>
        </div>
        <div class="layui-card-body layui-row">
            <div class="layui-form-item layui-col-md4">
                <label class="layui-form-label">上级菜单</label>
                <div class="layui-input-block">
                    <select name="parentid" xm-select="radio" xm-select-radio lay-verify="required" xm-select-search="">

                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-col-md4">
                <div class="layui-col-lg12">
                    <label class="layui-form-label">名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" value="{{$data->name ?? ''}}" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-col-md4">
                <div class="layui-col-lg12">
                    <label class="layui-form-label">是否菜单：</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="ismenu" lay-skin="switch" lay-text="是|否" value="1"  lay-filter="ismenu" {{(isset($data) && $data->ismenu == \App\Models\Permission::isMenuTrue) ? 'checked' : '' }}>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-col-md4">
                <div class="layui-col-lg12">
                    <label class="layui-form-label">规则：</label>
                    <div class="layui-input-block">
                        <textarea name="rule" placeholder="请输入内容" class="layui-textarea">{{$data->rule ?? ''}}</textarea>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-col-md4">
                <div class="layui-col-lg12">
                    <label class="layui-form-label">权重：</label>
                    <div class="layui-input-block">
                        <input type="number" min="0" step="1" name="weight" value="{{$data->weight ?? ''}}" lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-col-md4">
                <div class="layui-col-lg12">
                    <label class="layui-form-label">图标：</label>
                    <div class="layui-input-block">
                        <input type="text" name="icon" id="iconPicker" lay-filter="iconPicker" class="layui-input" value="{{$data->icon ?? ''}}">
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-col-md6">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit lay-filter="layui-form-submit">确 认</button>
                    {{isset($data) ? method_field('PUT') : ''}}
                    {{csrf_field()}}
                    <a class="layui-btn" href="{{url('admin/menu')}}" >返 回</a>
                </div>
            </div>
        </div>
        </form>
    </div>
@endsection

@section('script')
    <script src="/js/ajax.js"></script>
    <script>
        layui.use(['formSelects','iconPicker'], function(){
            var formSelects = layui.formSelects;
            var iconPicker = layui.iconPicker;

            iconPicker.render({
                // 选择器，推荐使用input
                elem: '#iconPicker',
                // 数据类型：fontClass/unicode，推荐使用fontClass
                type: 'fontClass',
                // 是否开启搜索：true/false
                search: true,
                page: true,
                limit:10,
                // 点击回调
                click: function (data) {
                    $('#iconPicker').val(data.icon);
                }
            });

            /**
             * 选中图标 （常用于更新时默认选中图标）
             * @param filter lay-filter
             * @param iconName 图标名称，自动识别fontClass/unicode
             */
            iconPicker.checkIcon('iconPicker',"{{$data->icon ?? ''}}");


            formSelects.data('radio', 'local', {
                arr: [{
                    "name": "Root",
                    "value": 0,
                    "selected" : "{{(isset($data) && $data->parentid == 0) ? 'selected' : ''}}",
                    "children":@json(\App\Models\Permission::getPermissionFormSelect(0,isset($data) ? $data->parentid : ($parentid ?? 0))),
                }]
            });

        });
    </script>
@endsection